package ace.module.stock.core.impl.dao.aggregate.helper;

import ace.cmp.util.AceNumberUtils;
import ace.cmp.util.AceStreamUtils;
import ace.module.stock.api.enums.WmsSalesQuantityObjectTypeEnum;
import ace.module.stock.core.impl.dao.entity.WmsSalesQuantity;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 销售数量 aggregate helper.
 *
 * @author Caspar
 */
@Slf4j
@AllArgsConstructor
@Component
public class WmsSalesQuantityAggregateHelper {

  public WmsSalesQuantity findByObjectIdAndObjectType(List<WmsSalesQuantity> wmsSalesQuantities, Long objectId, Integer objectType) {
    return AceStreamUtils.ofNullable(wmsSalesQuantities)
        .filter(p -> AceNumberUtils.isEquals(p.getObjectId(), objectId))
        .filter(p -> AceNumberUtils.isEquals(p.getObjectType(), objectType))
        .findFirst()
        .orElse(null);
  }

  public List<WmsSalesQuantity> getSkus(Collection<WmsSalesQuantity> wmsSalesQuantities) {
    return AceStreamUtils.ofNullable(wmsSalesQuantities)
        .filter(p -> AceNumberUtils.isEquals(p.getObjectType(), WmsSalesQuantityObjectTypeEnum.PRODUCT_SKU.getCode()))
        .collect(Collectors.toList());
  }
}